package com.hex.liyue.giftmodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.giftmodule.bean.HarvesGiftsBean;

import java.util.List;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterHarvestDetails extends RecyclerView.Adapter<AdapterHarvestDetails.MyHolder> {
    private OnItemClickListener onItemClickListener;
    private List<HarvesGiftsBean.DataBean.GiftListBean> lists;

    public AdapterHarvestDetails(List<HarvesGiftsBean.DataBean.GiftListBean> lists) {
        this.lists = lists;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(int position);
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_shopping_details, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        holder.rl_item_box.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClickListener(position);
            }
        });
        holder.tv_dis_desc.setText(lists.get(position).gift_brand);
        holder.tv_dis_name.setText(lists.get(position).gift_name);
        holder.tv_dis_num.setText("数量：x" + lists.get(position).status);
        holder.tv_dis_price.setText("金额：￥" + lists.get(position).price);
        Glide.with(LiYueApplication.getInstance())
                .load(lists.get(position).gift_url)
                .error(R.drawable.no_icon)
                .into(holder.iv_icon);
    }

    @Override
    public int getItemCount() {
        if (lists == null) {
            return 0;
        }
        return lists.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        RelativeLayout rl_item_box;
        TextView tv_dis_desc;
        TextView tv_dis_num;
        TextView tv_dis_price;
        TextView tv_dis_name;
        ImageView iv_icon;

        public MyHolder(View itemView) {
            super(itemView);
            rl_item_box = (RelativeLayout) itemView.findViewById(R.id.rl_item_box);
            tv_dis_desc = (TextView) itemView.findViewById(R.id.tv_dis_desc);
            tv_dis_num = (TextView) itemView.findViewById(R.id.tv_dis_num);
            tv_dis_price = (TextView) itemView.findViewById(R.id.tv_dis_price);
            tv_dis_name = (TextView) itemView.findViewById(R.id.tv_dis_name);
            iv_icon = (ImageView) itemView.findViewById(R.id.iv_icon);
        }
    }
}
